package com.jack.hhitseat.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jack.hhitseat.bean.LogSearch;
import com.jack.hhitseat.bean.Seat;
import com.jack.hhitseat.mapper.main.SeatMapper;
import com.jack.hhitseat.model.LayuiMap;

@Service
public class SeatService {
	@Autowired
	private SeatMapper seatMapper;

	public int countDay(String s, String e) {
		return seatMapper.countDay(s, e);
	}
	
	public int count(String devId, String accno, String d) {
		return seatMapper.count(devId, accno, d);
	}

	public void insert(Seat seat) {
		seatMapper.insert(seat);
	}

	public Object list(LogSearch logSearch) {
		logSearch.setPage((logSearch.getPage()-1) * logSearch.getLimit());
		
		LayuiMap<Seat> result = new LayuiMap<>();
		List<Seat> seats = new ArrayList<Seat>();
		
		try {
			seats = seatMapper.list(logSearch);
			result.setCount(seatMapper.countList(logSearch));
		}catch (Exception e) {
			e.printStackTrace();
			result.setCode("0");
			result.setData(null);
			return result;
		}
		result.setCode("0");
		result.setData(seats);
		return result;
	}

}
